﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using YfShlErp.BLL1;
using YfShlErp.Model;

namespace YfShlErp
{
    public partial class SellerinformationEntryForm : Form
    {
        private SellersBLL Sellers = new SellersBLL();

        private InquirySellersDataBLL inquiry1 = new InquirySellersDataBLL();

        [DllImport("user32.dll")]
        private static extern int ReleaseCapture();

        [DllImport("user32.dll")]
        private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

        public SellerinformationEntryForm()
        {
            InitializeComponent();
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(this.Handle, 0x00A1, 0x0002, 0);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        public void EnteringBtn_Click(object sender, EventArgs e)
        {
            double weight = int.Parse(NumberTxt.Text);
            string Name = NameTxt.Text;
            string Phone = PhoneNumberTxt.Text;
            string Type = VarietySelect.Text;
            double Price = double.Parse(NumberTxt.Text) * 0;
            switch (VarietySelect.Text)
            {
                case "大果":
                    var a = inquiry1.GetFruitPrice();
                    Price = double.Parse(NumberTxt.Text) * double.Parse(a[0].BigFP);
                    break;

                case "中果":
                    var b = inquiry1.GetFruitPrice();
                    Price = double.Parse(NumberTxt.Text) * double.Parse(b[0].MiddleFP);
                    break;

                case "小果":
                    var c = inquiry1.GetFruitPrice();
                    Price = double.Parse(NumberTxt.Text) * double.Parse(c[0].smallFP);
                    break;

                case "青果":
                    var d = inquiry1.GetFruitPrice();
                    Price = double.Parse(NumberTxt.Text) * double.Parse(d[0].GreenFP);
                    break;
            }

            if (Sellers.EnteringData(Name, Phone, Type, weight, Price))
            {
                MessageBox.Show("录入成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                MessageBox.Show("录入失败");
            }
        }
    }
}